package fi.uba.tecnicas.diseno.tp2.ui;

import context.TpContextFactory;
import java.io.IOException;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import modelo.Oferta;
import modelo.Producto;

/**
 * Form that allows editing of information about one client.
 *
 * @author Jiri Vagner, Jan Stola
 */
public class Tp2Manager extends javax.swing.JPanel {
    private static TpContextFactory cf;
    
    public Tp2Manager() throws IOException {
        initComponents();
    }


    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        sexButtonGroup = new javax.swing.ButtonGroup();
        productoPane = new javax.swing.JTabbedPane();
        productoPanel = new javax.swing.JPanel();
        firstNameLabel = new javax.swing.JLabel();
        ptipoProductoTextField = new javax.swing.JTextField();
        surnameLabel = new javax.swing.JLabel();
        pNombreTextField = new javax.swing.JTextField();
        maritalStatusLabel = new javax.swing.JLabel();
        ageLabel = new javax.swing.JLabel();
        pPrecioTextField = new javax.swing.JTextField();
        pMarcaTextField = new javax.swing.JTextField();
        firstNameLabel1 = new javax.swing.JLabel();
        pCodigoProductoTextField = new javax.swing.JTextField();
        pGuardarButton = new javax.swing.JButton();
        promoProductoPanel = new javax.swing.JPanel();
        Label = new javax.swing.JLabel();
        ppPorcentajeTextField = new javax.swing.JTextField();
        ppGuardaButton = new javax.swing.JButton();
        ppQueryTextField = new javax.swing.JTextField();
        Label1 = new javax.swing.JLabel();
        ofertaVentaPanel = new javax.swing.JPanel();
        fpLabel = new javax.swing.JLabel();
        ovQueryTextField = new javax.swing.JTextField();
        ovGuardarButton = new javax.swing.JButton();
        bancoVentaLabel3 = new javax.swing.JLabel();
        ovPorcentajeTextField = new javax.swing.JTextField();
        clientInfoLabel = new javax.swing.JLabel();
        validationMsgLabel = new javax.swing.JLabel();

        productoPanel.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        firstNameLabel.setText("Tipo:"); // NOI18N

        org.jdesktop.beansbinding.Binding binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, org.jdesktop.beansbinding.ELProperty.create("${client.firstName}"), ptipoProductoTextField, org.jdesktop.beansbinding.BeanProperty.create("text"), "firstName"); // NOI18N
        bindingGroup.addBinding(binding);

        surnameLabel.setText("Nombre:"); // NOI18N

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, org.jdesktop.beansbinding.ELProperty.create("${client.surname}"), pNombreTextField, org.jdesktop.beansbinding.BeanProperty.create("text"), "surname"); // NOI18N
        bindingGroup.addBinding(binding);

        pNombreTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                pNombreTextFieldActionPerformed(evt);
            }
        });

        maritalStatusLabel.setText("Marca:"); // NOI18N

        ageLabel.setText("Precio:"); // NOI18N

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, org.jdesktop.beansbinding.ELProperty.create("${client.age}"), pPrecioTextField, org.jdesktop.beansbinding.BeanProperty.create("text"), "age");
        bindingGroup.addBinding(binding);

        pMarcaTextField.setToolTipText("Marca");

        firstNameLabel1.setText("Codigo:"); // NOI18N

        pGuardarButton.setText("Guardar");
        pGuardarButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                pGuardarButtonActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout productoPanelLayout = new org.jdesktop.layout.GroupLayout(productoPanel);
        productoPanel.setLayout(productoPanelLayout);
        productoPanelLayout.setHorizontalGroup(
            productoPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(productoPanelLayout.createSequentialGroup()
                .addContainerGap()
                .add(productoPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(productoPanelLayout.createSequentialGroup()
                        .add(productoPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(firstNameLabel)
                            .add(surnameLabel)
                            .add(ageLabel)
                            .add(maritalStatusLabel)
                            .add(firstNameLabel1))
                        .add(7, 7, 7)
                        .add(productoPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(ptipoProductoTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 329, Short.MAX_VALUE)
                            .add(pNombreTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 329, Short.MAX_VALUE)
                            .add(productoPanelLayout.createSequentialGroup()
                                .add(pPrecioTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 117, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .add(0, 212, Short.MAX_VALUE))
                            .add(pMarcaTextField)
                            .add(org.jdesktop.layout.GroupLayout.TRAILING, pCodigoProductoTextField)))
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, productoPanelLayout.createSequentialGroup()
                        .add(0, 0, Short.MAX_VALUE)
                        .add(pGuardarButton)))
                .addContainerGap())
        );
        productoPanelLayout.setVerticalGroup(
            productoPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(productoPanelLayout.createSequentialGroup()
                .addContainerGap()
                .add(productoPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(firstNameLabel)
                    .add(ptipoProductoTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(productoPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(surnameLabel)
                    .add(pNombreTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(productoPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(maritalStatusLabel)
                    .add(pMarcaTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(productoPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(ageLabel)
                    .add(pPrecioTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(productoPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(firstNameLabel1)
                    .add(pCodigoProductoTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 65, Short.MAX_VALUE)
                .add(pGuardarButton))
        );

        productoPane.addTab("Producto", productoPanel);

        promoProductoPanel.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        Label.setText("Porcentaje:"); // NOI18N

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, org.jdesktop.beansbinding.ELProperty.create("${client.nickname}"), ppPorcentajeTextField, org.jdesktop.beansbinding.BeanProperty.create("text"), "nickname"); // NOI18N
        bindingGroup.addBinding(binding);

        ppGuardaButton.setText("Guardar");
        ppGuardaButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ppGuardaButtonActionPerformed(evt);
            }
        });

        ppQueryTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ppQueryTextFieldActionPerformed(evt);
            }
        });

        Label1.setText("Query:"); // NOI18N

        org.jdesktop.layout.GroupLayout promoProductoPanelLayout = new org.jdesktop.layout.GroupLayout(promoProductoPanel);
        promoProductoPanel.setLayout(promoProductoPanelLayout);
        promoProductoPanelLayout.setHorizontalGroup(
            promoProductoPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(promoProductoPanelLayout.createSequentialGroup()
                .addContainerGap()
                .add(promoProductoPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(promoProductoPanelLayout.createSequentialGroup()
                        .add(0, 0, Short.MAX_VALUE)
                        .add(ppGuardaButton))
                    .add(promoProductoPanelLayout.createSequentialGroup()
                        .add(promoProductoPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(Label)
                            .add(Label1))
                        .add(15, 15, 15)
                        .add(promoProductoPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(ppQueryTextField)
                            .add(ppPorcentajeTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 306, Short.MAX_VALUE))))
                .addContainerGap())
        );
        promoProductoPanelLayout.setVerticalGroup(
            promoProductoPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(promoProductoPanelLayout.createSequentialGroup()
                .addContainerGap()
                .add(promoProductoPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(Label)
                    .add(ppPorcentajeTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(promoProductoPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(Label1)
                    .add(ppQueryTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 115, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 68, Short.MAX_VALUE)
                .add(ppGuardaButton)
                .add(12, 12, 12))
        );

        productoPane.addTab("PromoProducto", promoProductoPanel);

        ofertaVentaPanel.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        fpLabel.setText("Query:"); // NOI18N

        ovGuardarButton.setText("Guardar");
        ovGuardarButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ovGuardarButtonActionPerformed(evt);
            }
        });

        bancoVentaLabel3.setText("Porcentaje:"); // NOI18N

        org.jdesktop.layout.GroupLayout ofertaVentaPanelLayout = new org.jdesktop.layout.GroupLayout(ofertaVentaPanel);
        ofertaVentaPanel.setLayout(ofertaVentaPanelLayout);
        ofertaVentaPanelLayout.setHorizontalGroup(
            ofertaVentaPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(ofertaVentaPanelLayout.createSequentialGroup()
                .addContainerGap()
                .add(bancoVentaLabel3)
                .add(23, 23, 23)
                .add(ofertaVentaPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(ovQueryTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 298, Short.MAX_VALUE)
                    .add(ovPorcentajeTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 298, Short.MAX_VALUE))
                .addContainerGap())
            .add(org.jdesktop.layout.GroupLayout.TRAILING, ofertaVentaPanelLayout.createSequentialGroup()
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .add(ovGuardarButton)
                .add(14, 14, 14))
            .add(ofertaVentaPanelLayout.createSequentialGroup()
                .add(6, 6, 6)
                .add(fpLabel)
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        ofertaVentaPanelLayout.setVerticalGroup(
            ofertaVentaPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(ofertaVentaPanelLayout.createSequentialGroup()
                .addContainerGap()
                .add(ofertaVentaPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(fpLabel)
                    .add(ovQueryTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 141, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 48, Short.MAX_VALUE)
                .add(ofertaVentaPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(bancoVentaLabel3)
                    .add(ovPorcentajeTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(ovGuardarButton)
                .addContainerGap())
        );

        productoPane.addTab("OfertaVenta", ofertaVentaPanel);

        clientInfoLabel.setFont(new java.awt.Font("Dialog", 0, 24)); // NOI18N
        clientInfoLabel.setText("Manejo de Productos:"); // NOI18N

        validationMsgLabel.setFont(new java.awt.Font("Dialog", 1, 11)); // NOI18N
        validationMsgLabel.setForeground(new java.awt.Color(255, 0, 0));

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(org.jdesktop.layout.GroupLayout.LEADING, productoPane)
                    .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
                        .add(clientInfoLabel)
                        .add(0, 0, Short.MAX_VALUE))
                    .add(org.jdesktop.layout.GroupLayout.LEADING, validationMsgLabel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(clientInfoLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 27, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(productoPane, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 256, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .add(validationMsgLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 18, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        bindingGroup.bind();
    }// </editor-fold>//GEN-END:initComponents

    private void pNombreTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pNombreTextFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_pNombreTextFieldActionPerformed

    private void pGuardarButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pGuardarButtonActionPerformed
        String codigoProducto = pCodigoProductoTextField.getText();
        String nombre = pNombreTextField.getText();
        String marca = pMarcaTextField.getText();
        String precio = pPrecioTextField.getText();
        String tipo =ptipoProductoTextField.getText();
        
        pCodigoProductoTextField.setText("");
        pNombreTextField.setText("");
        pMarcaTextField.setText("");
        pPrecioTextField.setText("");
        ptipoProductoTextField.setText("");
                  
        PriceConverter pc = new PriceConverter();
        BigDecimal dPrecio = pc.convertReverse(precio);
        Producto producto = new Producto(codigoProducto,tipo,nombre,marca,dPrecio);
        
        try {
            
            List<Producto> products = cf.getDbReader().readProducts();
            if (!products.contains(producto)){
                products.add(producto);
                cf.getDbWriter().writeProducts(products);
            }else{
                validationMsgLabel.setText("El Id ya existe para otro producto");
            }
            
        } catch (IOException ex) {
            Logger.getLogger(Tp2Manager.class.getName()).log(Level.SEVERE, null, ex);
            validationMsgLabel.setText("Fallo el acceso al json de productos");
        }
        
    }//GEN-LAST:event_pGuardarButtonActionPerformed

    private void ovGuardarButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ovGuardarButtonActionPerformed

        String query = ovQueryTextField.getText();
        String porcentaje = ovPorcentajeTextField.getText();
        
        ovQueryTextField.setText("");
        ovPorcentajeTextField.setText("");
                
        Integer porcentajeInteger = new Integer(porcentaje);
        
        
        Oferta ofertaVenta = new Oferta(porcentajeInteger,query);
        
        try {
            
            List<Oferta> ofertasVenta = cf.getDbReader().readOfferSell();
            if (!ofertasVenta.contains(ofertaVenta)){
                ofertasVenta.add(ofertaVenta);
                cf.getDbWriter().writeOfferSell(ofertasVenta);
            }else{
                validationMsgLabel.setText("La oferta de venta ya existe");
            }
            
        } catch (IOException ex) {
            Logger.getLogger(Tp2Manager.class.getName()).log(Level.SEVERE, null, ex);
            validationMsgLabel.setText("Fallo el acceso al json de ofertas de venta");
        }
    }//GEN-LAST:event_ovGuardarButtonActionPerformed

    private void ppGuardaButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ppGuardaButtonActionPerformed

        String porcentaje = ppPorcentajeTextField.getText();
        String query = ppQueryTextField.getText();
        
        ppQueryTextField.setText("");
        ppQueryTextField.setText("");
        
        Integer porcentajeInteger = new Integer(porcentaje);
        
        
        Oferta offerProducto = new Oferta(porcentajeInteger,query);

        try {

            List<Oferta> offerProducts = cf.getDbReader().readOfferProducts();
            if (!offerProducts.contains(offerProducto)){
                offerProducts.add(offerProducto);
                cf.getDbWriter().writeOfferProducts(offerProducts);
            }else{
                validationMsgLabel.setText("La oferta ya existe");
            }

        } catch (IOException ex) {
            Logger.getLogger(Tp2Manager.class.getName()).log(Level.SEVERE, null, ex);
            validationMsgLabel.setText("Fallo el acceso al json de ofertas de productos");
        }
    }//GEN-LAST:event_ppGuardaButtonActionPerformed

    private void ppQueryTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ppQueryTextFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_ppQueryTextFieldActionPerformed
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            javax.swing.UIManager.LookAndFeelInfo[] installedLookAndFeels=javax.swing.UIManager.getInstalledLookAndFeels();
            for (int idx=0; idx<installedLookAndFeels.length; idx++)
                if ("Nimbus".equals(installedLookAndFeels[idx].getName())) {
                    javax.swing.UIManager.setLookAndFeel(installedLookAndFeels[idx].getClassName());
                    break;
                }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Tp2Manager.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Tp2Manager.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Tp2Manager.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Tp2Manager.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        
        
        cf = new TpContextFactory();
        cf.init();
        
        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                javax.swing.JFrame frame = new javax.swing.JFrame("Store administration");
                frame.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
                try {
                    frame.getContentPane().add(new Tp2Manager());
                } catch (IOException ex) {
                    Logger.getLogger(Tp2Manager.class.getName()).log(Level.SEVERE, null, ex);
                }
                frame.pack();
                frame.setVisible(true);
            }
        });
        
        
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel Label;
    private javax.swing.JLabel Label1;
    private javax.swing.JLabel ageLabel;
    private javax.swing.JLabel bancoVentaLabel3;
    private javax.swing.JLabel clientInfoLabel;
    private javax.swing.JLabel firstNameLabel;
    private javax.swing.JLabel firstNameLabel1;
    private javax.swing.JLabel fpLabel;
    private javax.swing.JLabel maritalStatusLabel;
    private javax.swing.JPanel ofertaVentaPanel;
    private javax.swing.JButton ovGuardarButton;
    private javax.swing.JTextField ovPorcentajeTextField;
    private javax.swing.JTextField ovQueryTextField;
    private javax.swing.JTextField pCodigoProductoTextField;
    private javax.swing.JButton pGuardarButton;
    private javax.swing.JTextField pMarcaTextField;
    private javax.swing.JTextField pNombreTextField;
    private javax.swing.JTextField pPrecioTextField;
    private javax.swing.JButton ppGuardaButton;
    private javax.swing.JTextField ppPorcentajeTextField;
    private javax.swing.JTextField ppQueryTextField;
    private javax.swing.JTabbedPane productoPane;
    private javax.swing.JPanel productoPanel;
    private javax.swing.JPanel promoProductoPanel;
    private javax.swing.JTextField ptipoProductoTextField;
    private javax.swing.ButtonGroup sexButtonGroup;
    private javax.swing.JLabel surnameLabel;
    private javax.swing.JLabel validationMsgLabel;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables
    
}
